﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Application.Admin.Article
{
    public class ArticleSightService : IArticleSightService
    {
        Domain.Uow.IRepository<Domain.Entity.ArticleSight> articleSightRepository;

        public ArticleSightService(Domain.Uow.IRepository<Domain.Entity.ArticleSight> sight)
        {
            if (sight == null)
            {
                throw new ArgumentNullException("articleSightRepository is null");
            }
            articleSightRepository = sight;
        }

        public Domain.Entity.ArticleSight Add(Domain.Entity.ArticleSight add, Domain.Entity.User operUser)
        {
            if (add == null) return add;
            articleSightRepository.Add(add);
            articleSightRepository.Uow.Commit();
            return add;
        }

        public bool Delete(Domain.Entity.ArticleSight delete, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                delete.State = false;
                articleSightRepository.Modify(delete);
                articleSightRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(Domain.Entity.ArticleSight delete, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                articleSightRepository.Delete(delete);
                articleSightRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Delete(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = articleSightRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                item.State = false;
                articleSightRepository.Modify(item);
            }
            try
            {
                articleSightRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = articleSightRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                articleSightRepository.Delete(item);
            }
            try
            {
                articleSightRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Modify(Domain.Entity.ArticleSight modify, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                articleSightRepository.Modify(modify);
                articleSightRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public Domain.Entity.ArticleSight Get(int id)
        {
            var data = articleSightRepository.Get(id);
            return data;
        }

        public IQueryable<Domain.Entity.ArticleSight> GetList()
        {
            var data = articleSightRepository.GetList();
            return data;
        }

    }
}
